#include <bits/stdc++.h>
using namespace std;
int d[1000005],vv[1000005],a[1000005],p[1000005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t,n,m,l,v;
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n>>m>>l>>v;
        int cnt=0;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>vv[i]>>a[i];
            if(vv[i]>v){
                cnt++;
            }
        }
        //cout<<cnt<<endl;
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        if(p[m]>=d[n]){
            cout<<cnt<<" "<<1;
            return 0;
        }
        else{
            for(int i=1;i<=n;i++){
                if(p[m]<d[i]){
                        //cout<<i<<endl;
                    cout<<cnt-(n-i+1)<<" "<<1;
                    return 0;
                }
            }
        }
    }
    return 0;
}
